var mongoose = require('mongoose');
require('../model/merchant.model');
var merchantModel = mongoose.model('Merchant');
var resource = require('../utils/resourceUtil');

module.exports={
    findByMerchantId:findByMerchantId,
    findByIdList:findByIdList
}


function findByMerchantId(merchantid,callBack){
    merchantModel.findOne({'_id':merchantid},function(err,doc){
        callBack(err,doc);
    }).populate('dish');
}

// function addOrder(orderId,merchantId,callBack){
//     merchantModel.update({'_id':merchantId},{$push:{'order':orderId}},function (err,doc){
//         callBack(err,doc);
//     });
// }

function findByIdList(callBack){
    resource.getMerchantList(function (data) {
        merchantModel.find(
            {
                _id:{$in:data}
            },
            function (err,doc){
                callBack(err,doc);
            }).populate('dish');
        console.log(data);
    });

    // var merchantList = ["954876aa-cceb-47b9-b41b-b09baf283dad"];

}

